﻿
/// <summary>
/// The class for outputting the results of the algorithm to XML
/// 
/// Made by dylan snel & Pascal schotman
/// </summary>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KentekenHerkenning
{
    class XMLoutput
    {
        public static string XML;
        public static void saveOutPut(List<Result> Results)
        {
            

           XML = "<?xml version=\"1.0\"?>\r\n"
                   + " <testresults>";

           foreach (Result r in Results)
           {
               XML += "<image filename=\""+r.originalPath+"\">\r\n"
                    + " <license_plate>\r\n"
                    + " <location>\r\n"
                    + " <upperLeft x=\"" + r.TopLeft.X + "\" y=\"" + r.TopLeft.Y + "\" />\r\n"
                    + " <upperRight x=\"" + r.TopRight.X + "\" y=\"" + r.TopRight.Y + "\" />\r\n"
                    + " <lowerLeft x=\"" + r.BottomLeft.X + "\" y=\"" + r.BottomLeft.Y + "\" />\r\n"
                    + " <lowerRight x=\"" + r.BottomRight.X + "\" y=\"" + r.BottomRight.Y + "\" />\r\n"
                    + " </location>\r\n"
                    + " <text>"+r.foundLicensePlate+"</text>\r\n"
                    + " </license_plate>\r\n"
                    + " <execution_time>"+r.Time+" ms</execution_time>\r\n"
                    + " </image>";
           }
           XML += "</testresults>";
           SaveToFile(System.Reflection.Assembly.GetExecutingAssembly().Location.Replace("FinalKentekenHerkenning.exe", "") + "XMLoutput_team6.xml");

        }
        public static void SaveToFile(string filename)
        {
            System.IO.StreamWriter file = new System.IO.StreamWriter(filename);
            file.WriteLine(XML);

            file.Close();


        }
    }
    
}
